package com.atguigu.spring6.resource;

import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.io.InputStream;

// 访问类路径下的资源
public class ClassPathResourceDemo {

    public static void main(String[] args) {
        try {
            loadClassPathResource("atguiguNew.txt");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    private static void loadClassPathResource(String str) throws IOException {
        // 创建对象
        ClassPathResource resource = new ClassPathResource(str);
        // 获取类路径下的资源
        System.out.println(resource.getFilename());
        System.out.println(resource.getDescription());
        InputStream inputStream = resource.getInputStream();
        byte[] bytes = new byte[1024];
        while (inputStream.read(bytes) != -1) {
            System.out.println(new String(bytes));
        }
    }
}
